package com.example.springinitialization.utils;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.digest.DigestUtil;


public class StringUtil {

    /**
     * 获取随机的n位数
     */
    public static int getRandomNCount(int n) {
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++) {
            String s = RandomUtil.randomNumbers(1);
            sb.append(s);
        }
        return Integer.parseInt(sb.toString());
    }

    /**
     * 将字符串转为md5存储
     * @param str
     * @return
     */
    public static String transferStrToMD5(String str) {
        return DigestUtil.md5Hex(str);
    }
}
